﻿/********************************************
 * 这个类继承自QWidget                        *
 * 这个类实现了一个自定义的标题栏                *
 * 若要定制标题栏，请直接修改此类                *
 ********************************************/

#pragma once

#include <QString>
#include <QColor>
#include <QPushButton>
#include <QLabel>
#include <QWidget>

#define TITLE_BAR_DEFAULT_HEIGHT 30
#define TITLE_BAR_DEFAULT_BACKGROUND_COLOR QColor(68, 29, 238)

class WindowTitleBar : public QWidget
{
    Q_OBJECT

public:
    explicit WindowTitleBar(QWidget *parent = Q_NULLPTR);
    ~WindowTitleBar();

protected:
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    virtual void mouseDoubleClickEvent(QMouseEvent *event);

signals:
    void onMousePressed();
    void onMouseReleased();
    void onMouseDoubleClicked();
    void onIconButtonClicked();
    void onMinimizeButtonClicked();
    void onMaximizeButtonClicked();
    void onCloseButtonClicked();
    void windowTitleBarInitialized();

public slots:
    void setTitleText(const QString &m_text);
    QString titleText() const;
    void setTitleTextAlignCenter(bool m_center = true);
    void setTitleBarBackgroundColor(QColor m_color = TITLE_BAR_DEFAULT_BACKGROUND_COLOR);
    QColor titleBarBackgroundColor() const;
    void setTitleBarHeight(int m_height = TITLE_BAR_DEFAULT_HEIGHT);
    int titleBarHeight() const;
    void setIconButtonVisible(bool m_visible = true);
    bool iconButtonVisible() const;
    void setTitleLabelVisible(bool m_visible = true);
    bool titleLabelVisible() const;
    void setMinimizeButtonVisible(bool m_visible = true);
    bool minimizeButtonVisible() const;
    void setMaximizeButtonVisible(bool m_visible = true);
    bool maximizeButtonVisible() const;
    void setCloseButtonVisible(bool m_visible = true);
    bool closeButtonVisible() const;

private slots:
    void onInitialize();

private:
    QPushButton *m_pIconButton;
    QLabel *m_pTitleLabel;
    QPushButton *m_pMinimizeButton;
    QPushButton *m_pMaximizeButton;
    QPushButton *m_pCloseButton;
};
